var tubiao = {
	init : function(){
		var boss = this;
		boss.initLayout();
		boss.initEvent();
	},
	initLayout : function(){
		var boss = this;
		if(boss.getQueryString("tag") == "jingli"){
			$(".anjiantubiao-div, .jingwuxinxitubiao-div").hide();
			boss.initTeamPicture(boss.getQueryString("fullid"));
		}else if(boss.getQueryString("tag") == "jingqing"){
			$(".duiwutubiao-div, .jingwuxinxitubiao-div").hide();
			var fullid = boss.getQueryString("fullid").split("-");
			var pid = fullid[fullid.length-2];
			boss.initAlertPicture(pid, fullid.length);
		}else if(boss.getQueryString("tag") == "jingwuxinxi"){
			$(".duiwutubiao-div, .anjiantubiao-div").hide();
			boss.initPoliceInformationPicture(boss.getQueryString("fullid"));
		}
	},
	initEvent : function(){
		
	},
	getQueryString : function(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) return unescape(r[2]);
		return null;
    },
    initTeamPicture : function(fullid){
    	var row = modelDao.getJingliData(fullid);
    	var data_count = [];
    	var data_sum = [];
    	var data_num = [];
    	for(var i = 0; i < row.length; i++){
    		data_count.push(row[i].COUNT);
    		data_sum.push(row[i].SUM);
    		data_num.push(row[i].NUM);
    	}
		$("#duiwutubiao").highcharts({
			chart : {
				type : 'column'
			},
			title : {
				text : '警力'
			},
			xAxis : {
				categories : [ '民警', '第一支队', '第二支队', '第三支队', '第四支队', '第五支队' ]
			},
			yAxis : {
				labels: {
                    format: '{value}',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    }
                },
                title: {
                    text: '人数（人）',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    }
                }
			},
			tooltip: {
                valueSuffix: ' 人'
            },
			plotOptions: {
	            column: {
	                pointPadding: 0.2,
	                borderWidth: 0
	            }
	        },
	        series : [{
	        	name : '队伍人数',
	        	data : data_count
	        }, {
	        	name : '终端人数',
	        	data : data_sum
	        }, {
	        	name : '安装App数',
	        	data : data_num
	        }]
	        
		});
	},
	initAllPicture : function(){
		$("#tubiao").highcharts({
			chart : {
				zoomType : 'xy'
			},
			title : {
				text : '警力、警情图表'
			},
			xAxis: [{
                categories: ['一月', '二月', '三月', '四月', '五月', '六月',
                    '七月', '八月', '九月', '十月', '十一月', '十二月']
            }],
            yAxis : [{
                labels: {
                    format: '{value}',
                    style: {
                        color: Highcharts.getOptions().colors[0]
                    }
                },
            	title: {
                    text: '人数（人）',
                    style: {
                        color: Highcharts.getOptions().colors[0]
                    }
                },
                opposite: true
            }, {
            	labels: {
                    format: '{value}',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    }
                },
                title: {
                    text: '案件数量（件）',
                    style: {
                        color: Highcharts.getOptions().colors[1]
                    }
                }
            }],
            legend: {
                layout: 'vertical',
                align: 'right',
                x: -100,
                verticalAlign: 'top',
                y: 10,
                floating: true,
                backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
            },
            series: [{
                name: '队伍人员总数',
                type: 'column',
                yAxis: 1,
                data: [2261, 2261, 2261, 2261, 2261, 2261, 2261, 2261, 2261, 2261, 2261, 2261],
                tooltip: {
                    valueSuffix: ' 人'
                }
            }, {
                name: '终端人员总数',
                type: 'column',
                yAxis: 1,
                data: [1166, 1210, 1342, 1342, 1512, 1569, 1674, 1693, 1759, 1800, 1856, 1923],
                tooltip: {
                    valueSuffix: ' 人'
                }
            }, {
            	name: '巡逻里程（公里）',
            	type: 'column',
            	yAxis: 1,
            	data: [2356, 2441, 2763, 2554, 2862, 2666, 2713, 2657, 2456, 2657, 2778, 2467],
            	tooltip: {
            		valueSuffix: ' 公里'
            	}
            }, {
                name: '案件数量',
                type: 'spline',
                data: [250, 231, 216, 213, 207, 186, 185, 192, 173, 170, 164, 146],
                tooltip: {
                    valueSuffix: ' 件'
                }
            }]
		});
	},
	initAlertPicture : function(pid, code){
		var row = eval(modelDao.getJingQingData(pid, code));
		var options = {
			chart: {
				renderTo: 'anjiantubiao'
			},
			title: {
				text: '警情趋势图'
			},
			xAxis: {
				categories: ['违法犯罪', '刑事', '治安', '八类', '两抢', '抢劫', '飞车抢夺', '盗窃总', 
				     '入室盗窃', '盗窃汽车', '盗窃摩托车/电动车', '诈骗']
			},
			yAxis: {
	            title: {
	                text: '案件数量 （件）'
	            },
	            plotLines: [{
	                value: 0,
	                width: 1,
	                color: '#808080'
	            }]
			},
			tooltip: {
	            valueSuffix: ' 件'
	        },
	        legend: {
	            layout: 'vertical',
	            align: 'right',
	            verticalAlign: 'middle',
	            borderWidth: 0
	        },
	        series: []
		};
		for(var i = 0; i < row.length; i++){
			var data = [];
			data.push(row[i].illegalCrime);
			data.push(row[i].criminal);
			data.push(row[i].publicOrder);
			data.push(row[i].eightCategory);
			data.push(row[i].rob);
			data.push(row[i].robbery);
			data.push(row[i].robberyByCar);
			data.push(row[i].theftOfAll);
			data.push(row[i].theftInRoom);
			data.push(row[i].theftCar);
			data.push(row[i].theftMoto);
			data.push(row[i].fraud);
			options.series.push({
				name: row[i].deptname,
				data: data
			});
		}
		var chart = new Highcharts.Chart(options);
	},
	initPoliceInformationPicture : function(fullid){
		var row = eval(modelDao.getJingwuxinxiData(fullid));
		var pid = fullid.split("-")[fullid.split("-").length-2];
		var org = modelDao.getOrgData(pid);
		var data = [];
		var count_wu = [];
		var count_ch = [];
		var count_ot = [];
		for(var i = 0; i < org.length; i++){
			data.push(org[i].deptname);
		}
		for(var i = 0; i < row.length; i++){
			if(row[i].TYPE == "物业式小区"){
				count_wu.push(row[i].NUM);
			}else if(row[i].TYPE == "城中村小区"){
				count_ch.push(row[i].NUM);
			}else if(row[i].TYPE == "其他（独栋）"){
				count_ot.push(row[i].NUM);
			}
		}
		$("#jingwuxinxitubiao").highcharts({
			chart: {
				type : 'column'
			},
			title: {
				text: '警务信息'
			},
			xAxis: {
				categories: data
			},
			yAxis: {
                labels: {
                    format: '{value}',
                    style: {
                        color: Highcharts.getOptions().colors[0]
                    }
                },
            	title: {
                    text: '场所（套）',
                    style: {
                        color: Highcharts.getOptions().colors[0]
                    }
                }
			},
			tooltip: {
                shared: true,
                valueSuffix: ' 栋'
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
            },
            series: [{
            	name: '物业式小区',
            	data: count_wu
            }, {
            	name: '城中村小区',
            	data: count_ch
            }, {
            	name: '其他（独栋）',
            	data: count_ot
            }]
		});
	}
};
$(function(){
	tubiao.init();
});